using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Noebe.MemoryCaches.Core;

namespace Pixysoft.Framework.Noebe.MemoryCaches
{
    class SettingHelper
    {
        CacheNoebeConfiguration settings = new CacheNoebeConfiguration();

        private static volatile SettingHelper instance;

        private static object syncRoot = new Object();

        public static SettingHelper Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        instance = new SettingHelper();
                    }
                }

                return instance;

            }
        }

        public static void Load()
        {
            try
            {
                Instance.settings = Pixysoft.Framework.Configurations.Configuration.GetConfiguration<
                    CacheNoebeConfiguration>();
            }
            catch
            {
                Instance.settings = new CacheNoebeConfiguration();
            }

            if (Instance.settings == null)
                Instance.settings = new CacheNoebeConfiguration();

            Instance.settings.Verify();
        }

        public static CacheNoebeConfiguration Configuration
        {
            get
            {
                return Instance.settings;
            }

        }

        public static INoebeManager GetManager(ICacheSetting setting)
        {
            INoebeManager manager = setting.GetManager();

            if (manager == null)
                return NoebeManagerAdapter.Instances[StringHelper.global_framework_id];

            return manager;
        }


        public static INoebeManager GetManager(string settingName)
        {
            return GetManager(Configuration.Get(settingName));
        }
    }
}
